package org.liuhy
{
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.core.Application;
	import mx.core.DragSource;
	import mx.core.UIComponent;
	import mx.events.DragEvent;
	import mx.managers.DragManager;
	
	public class FlowNode extends UIComponent
	{
		public var _top_node:TopNode;
		public var _bottom_node:BottomNode;
		public var _left_node:LeftNode;
		public var _right_node:RightNode;
		
		public var _inLine:ULine = null;		//进入线（即箭头线）
		public var _outLine:ULine = null;		//由节点引出线（即出去的线）
		
		private function _wrap_focus_node(p_focusNode:FocusNode,p_type:String):void{
			p_focusNode.width = 10;
			p_focusNode.height = 10;
			p_focusNode.setStyle("borderStyle","solid");
			p_focusNode.setStyle("borderColor","#000000");
			p_focusNode.setStyle("backgroundColor","#FFFFFF");	
			p_focusNode._flow_node_type = p_type;		
			this.addChild(p_focusNode);			
			p_focusNode.addEventListener(DragEvent.DRAG_ENTER,onDragEnter);
			p_focusNode.addEventListener(DragEvent.DRAG_DROP,p_focusNode.arrowLineNodeDrop);
			p_focusNode.addEventListener(DragEvent.DRAG_EXIT,onDragExit);
		}

		public function FlowNode()
		{
			this.x = 20;
			this.y = 20;
			this.width = 100;
			this.height = 75;			
			this.addEventListener(MouseEvent.MOUSE_DOWN,startDragging);
			this.addEventListener(MouseEvent.MOUSE_UP,stopDragging);
			this._top_node 		= new Node(this.width/2-5,0);
			this._left_node 	= new Node(0,this.height/2-5);
			this._right_node 	= new Node(this.width-10,this.height/2-5);
			this._bottom_node	= new Node(this.width/2-5,this.height-10);		
			this._wrap_focus_node(this._top_node,"TOP");
			this._wrap_focus_node(this._left_node,"LEFT");
			this._wrap_focus_node(this._right_node,"RIGHT");
			this._wrap_focus_node(this._bottom_node,"BOTTOM");			
		}
		
		private function dragit(event:MouseEvent):void{
			var dragInitiator:FlowNode = event.currentTarget as FlowNode;
			// Create a DragSource object.
			var dragSource:DragSource = new DragSource();			
			// Add the data to the object.			
//			dragSource.addData(value, 'value');			
			// Create a copy of the coin image to use as a drag proxy.
			var dragProxy:FlowNode = new FlowNode();			
			// Call the DragManager doDrag() method to start the drag.			
			DragManager.doDrag(dragInitiator, dragSource, event);
		}
//		private function onDragEnter(event:DragEvent):void{
//		
//		}
		
	
		private function onDragExit(event:DragEvent):void{
			
			//移除
//			var _n:Node = Node(event.currentTarget);			
//			var _uLine:ULine = event.dragSource.dataForFormat("line") as ULine;
//			var _moveNode:Node = event.dragInitiator as Node;
//			if(null==_uLine.preLine && "F"==_moveNode._type){		
//				Alert.show("remove toline");		
//				this._toLine = null;
//				_uLine._from_flow_node = null;
//			}
//			if(null==_uLine.nextLine && "T"==_moveNode._type){
//				this._fromLine = null;
//				_uLine._to_flow_node = null;
//				Alert.show("remove fromline");
//			}
		}
		private function _onArrowDrop(p_focusNode:Node,p_uLine:ULine,p_moveNode:Node):void{
			//移动箭头；
			if(null!=p_uLine.in_flow_focusNode)	{
				var _fn:FlowNode = p_uLine.in_flow_focusNode.parent as 	FlowNode;
				_fn._outLine = null;
			}
//			if(p_uLine.x1 ==p_uLine.x2 ){
				//竖线；
				if("LEFT"==p_focusNode._flow_node_type){
					this._onLeft_ArrowDrop(p_focusNode,p_uLine,p_moveNode);					
				}else if("RIGHT"==p_focusNode._flow_node_type){
					this._onRight_ArrowDrop(p_focusNode,p_uLine,p_moveNode);			
				}else if("TOP"==p_focusNode._flow_node_type){
					this._onTop_ArrowDrop(p_focusNode,p_uLine,p_moveNode);	
				}else{					
					p_uLine.arrowLineNode.x = this.x	+	p_focusNode.x;
					p_uLine.arrowLineNode.y = this.y	+	p_focusNode.y;
					p_uLine.in_flow_focusNode = p_focusNode;
//					_uLine.drawLine();
					p_uLine._reArrowDrawLine(p_uLine.arrowLineNode);
					
					p_focusNode.setStyle("backgroundColor","#ffffff");
					this._outLine = p_uLine;			
				}	
//				else{
//					p_uLine.toNode.x = this.x	+	p_focusNode.x;
//					p_uLine.toNode.y = this.y	+	p_focusNode.y;
//					p_uLine._to_flow_node = p_focusNode;
////					_uLine.drawLine();
//					p_uLine._reArrowDrawLine(p_uLine.toNode);					
//					p_focusNode.setStyle("backgroundColor","#ffffff");
//					this._fromLine = p_uLine;	
//				}
//			}else{
				//横线;
					
//			}
		}
		//左侧节点,箭头放下
		private function _onLeft_ArrowDrop(p_focusNode:Node,p_uLine:ULine,p_moveNode:Node):void{
//			//竖线(Ok)
			if(p_uLine.x1	==	p_uLine.x2){
				if((this.x+p_focusNode.x - p_uLine.x2)>0){
					//  |     
					//  |     
					///   ---+---
					///   |      |
					//    +      +
					//    |      |
					//	  ---+---
					//箭头线在流程节点的左侧;
					//1.创建一条横线,坐标(_uLine.x1,_n.y)-(_n.x,_n.y)
					var _line1:ULine = new ULine(p_uLine.x1,this.y+p_focusNode.y,this.x+p_focusNode.x,this.y+p_focusNode.y,this.parent as Application);
					//2.创建竖线,坐标(this.x1,this.y1)-(_uLine.x1,_n.y);
					var _line2:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line1.x1,_line1.y1,this.parent as Application);
					_line2.nextLine	 = _line1;
					_line1.preLine 	 = _line2;
					_line2.preLine = p_uLine.preLine;
					if(null!=p_uLine.preLine){
						p_uLine.preLine.nextLine = _line2;
					}
					LineUtils.removeLine(p_uLine);
					_line2.drawLine();
					_line1.drawLine();							
					_line1.in_flow_focusNode = p_focusNode;
					this._outLine = _line1;
				}else{
					//       |
					//       |
					///   ---+---
					///   |      |
					//    +      +
					//    |      |
					//	  ---+---
					//箭头线在流程左侧节点的右侧;
					if(null!=p_uLine.preLine){
						var _line1:ULine = new ULine(this.x+p_focusNode.x-40,this.y + p_focusNode.y,this.x+p_focusNode.x,this.y + p_focusNode.y,this.parent as Application);								
						var _line2:ULine = new ULine(_line1.x1,p_uLine.y1,_line1.x1,_line1.y1,this.parent as Application);	
						var _line3:ULine = new ULine(p_uLine.preLine.x1,p_uLine.preLine.y1,_line2.x1,_line2.y1,this.parent as Application);	
						_line1.preLine 	= _line2;
						_line2.nextLine = _line1;
						_line2.preLine  = _line3;
						_line3.nextLine = _line2;
						_line3.preLine = p_uLine.preLine.preLine;
						if(null!=p_uLine.preLine.preLine){
							p_uLine.preLine.preLine.nextLine = _line3;
						}
						LineUtils.removeLine(p_uLine.preLine);
						LineUtils.removeLine(p_uLine);	
						_line1.drawLine();
						_line2.drawLine();
						_line3.drawLine();
						_line1.in_flow_focusNode = this._left_node;
						_outLine = _line1;	
						p_focusNode.setStyle("backgroundColor","#ffffff");
					}else{
						var _line1:ULine = new ULine(this.x+p_focusNode.x-40,this.y + p_focusNode.y,this.x+p_focusNode.x,this.y + p_focusNode.y,this.parent as Application);
						var _y2:int = p_uLine.y1 + (p_uLine.y2-p_uLine.y1)/2;//
						var _line2:ULine = new ULine(_line1.x1,_y2,_line1.x1,_line1.y1,this.parent as Application);	
						var _line3:ULine = new ULine(p_uLine.x1,_y2,_line2.x1,_line2.y1,this.parent as Application);
						var _line4:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line3.x1,_line3.y1,this.parent as Application);
						_line1.preLine 	= _line2;
						_line2.nextLine = _line1;
						_line2.preLine 	= _line3;
						_line3.nextLine = _line2;
						_line3.preLine 	= _line4;
						_line4.nextLine = _line3;
						_line4.preLine = p_uLine.preLine;
						if(null!=p_uLine.preLine){
							p_uLine.preLine.nextLine = _line4;
						}
						LineUtils.removeLine(p_uLine);	
						_line1.drawLine();
						_line2.drawLine();
						_line3.drawLine();
						_line4.drawLine();	
						_line1.in_flow_focusNode = this._left_node;
//						var _fn:FlowNode = p_uLine._to_flow_node.parent as 	FlowNode;
						this._outLine = _line1;	
						p_focusNode.setStyle("backgroundColor","#ffffff");
					}
				}
			}else if(p_uLine.y1	==	p_uLine.y2){
				if(this.x + p_focusNode.x > p_uLine.x2){
					if(null==p_uLine.preLine){
						//一条横线;
						var _x2:int = p_uLine.x1 + (this.x + p_focusNode.x -p_uLine.x1)/2;//
						var _line1:ULine = new ULine(_x2,this.y + p_focusNode.y,this.x+p_focusNode.x,this.y + p_focusNode.y,this.parent as Application);

						var _line2:ULine = new ULine(_x2,p_uLine.y2,_line1.x1,_line1.y1,this.parent as Application);	
						var _line3:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line2.x1,_line2.y1,this.parent as Application);
					
						_line1.preLine 	= _line2;
						_line2.nextLine = _line1;
						_line2.preLine 	= _line3;
						_line3.nextLine = _line2;
						_line3.preLine 	= p_uLine.preLine;
						_line3.out_flow_focusNode = p_uLine.out_flow_focusNode;
						if(null!=p_uLine.out_flow_focusNode){
							var _flowNode:FlowNode = p_uLine.out_flow_focusNode.parent as FlowNode;
							_flowNode._inLine = _line3;
						}
						LineUtils.removeLine(p_uLine);	
						_line1.drawLine();
						_line2.drawLine();
						_line3.drawLine();
						_line1.in_flow_focusNode = this._left_node;
						this._outLine = _line1;	
						p_focusNode.setStyle("backgroundColor","#ffffff");
						
					}else{
						p_uLine.arrowLineNode.x = this.x	+	p_focusNode.x;
						p_uLine.arrowLineNode.y = this.y	+	p_focusNode.y;
						p_uLine.in_flow_focusNode = p_focusNode;
						p_uLine._reArrowDrawLine(p_uLine.arrowLineNode);				
						p_focusNode.setStyle("backgroundColor","#ffffff");
						this._outLine = p_uLine;
					}
				}else{
					////     ----
					///   ---+---
					///   |      |
					//    +      +
					//    |      |
					//	  ---+---
					var _line1:ULine = new ULine(this.x+p_focusNode.x-40,this.y + p_focusNode.y,this.x+p_focusNode.x,this.y + p_focusNode.y,this.parent as Application);
					var _y2:int = p_uLine.y1 + (p_uLine.y2-p_uLine.y1)/2;//
					var _line2:ULine = new ULine(_line1.x1,p_uLine.y1,_line1.x1,_line1.y1,this.parent as Application);	
					var _line3:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line2.x1,_line2.y1,this.parent as Application);
				
					_line1.preLine 	= _line2;
					_line2.nextLine = _line1;
					_line2.preLine 	= _line3;
					_line3.nextLine = _line2;
					_line3.preLine 	= p_uLine.preLine;

					if(null!=p_uLine.preLine){
						p_uLine.preLine.nextLine = _line3;
					}
					LineUtils.removeLine(p_uLine);	
					_line1.drawLine();
					_line2.drawLine();
					_line3.drawLine();
					_line1.in_flow_focusNode = this._left_node;
					this._outLine = _line1;	
					p_focusNode.setStyle("backgroundColor","#ffffff");
				}
				
			}			
		}
		//左侧节点,箭头放下
		private function _onRight_ArrowDrop(p_focusNode:Node,p_uLine:ULine,p_moveNode:Node):void{
			if(p_uLine.x2 - (this.x+p_focusNode.x )>10){
				//箭头线在流程节点的左侧;
				//1.创建一条横线,坐标(_uLine.x1,_n.y)-(_n.x,_n.y)
				var _line1:ULine = new ULine(p_uLine.x1,this.y+p_focusNode.y,this.x+p_focusNode.x,this.y+p_focusNode.y,this.parent as Application);
				//2.创建竖线,坐标(this.x1,this.y1)-(_uLine.x1,_n.y);
				var _line2:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line1.x1,_line1.y1,this.parent as Application);
				_line2.nextLine	 = _line1;
				_line1.preLine 	 = _line2;
				LineUtils.removeLine(p_uLine);
				_line2.drawLine();
				_line1.drawLine();
				_line1.in_flow_focusNode = p_focusNode;
				this._outLine = _line1;
			}else{							
				//距离非常近;
				p_uLine.arrowLineNode.x = this.x	+	p_focusNode.x;
				p_uLine.arrowLineNode.y = this.y	+	p_focusNode.y;
				p_uLine.in_flow_focusNode = p_focusNode;
				p_uLine._reArrowDrawLine(p_uLine.arrowLineNode);
				p_focusNode.setStyle("backgroundColor","#ffffff");
				this._outLine = p_uLine;
			}		
		}
		private function _onTop_ArrowDrop(p_focusNode:Node,p_uLine:ULine,p_moveNode:Node):void{
			//横线；
			if(p_uLine.x1	==	p_uLine.x2){
				
			}else if(p_uLine.y1	==	p_uLine.y2){
				//竖线；
				if(this.y + p_focusNode.y > p_uLine.y2){
					//箭头在上方流程节点的上方
					//1.创建一条横线,坐标(_uLine.x1,_n.y)-(_n.x,_n.y)
					var _line1:ULine = new ULine(this.x+p_focusNode.x,p_uLine.y1,this.x+p_focusNode.x,this.y+p_focusNode.y,this.parent as Application);
					//2.创建竖线,坐标(this.x1,this.y1)-(_uLine.x1,_n.y);
					var _line2:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line1.x1,_line1.y1,this.parent as Application);
					_line1.preLine 	 = _line2;
					_line2.nextLine	 = _line1;
					_line2.preLine 	 = p_uLine.preLine;
					if(null!=p_uLine.preLine){
						p_uLine.preLine.nextLine = _line2;
					}
					LineUtils.removeLine(p_uLine);
					_line2.drawLine();
					_line1.drawLine();
					_line1.in_flow_focusNode = p_focusNode;
					this._outLine = _line1;
				}else{	
					//箭头在流程节点的下方	
					var _line1:ULine = new ULine(this.x+p_focusNode.x,this.y + p_focusNode.y-40,this.x+p_focusNode.x,this.y + p_focusNode.y,this.parent as Application);
					var _x2:int = p_uLine.x1 + (p_uLine.x2-p_uLine.x1)/2;					
					var _line2:ULine = new ULine(_x2,_line1.y1,_line1.x1,_line1.y1,this.parent as Application);	
					var _line3:ULine = new ULine(_x2,p_uLine.y1,_line2.x1,_line2.y1,this.parent as Application);
					var _line4:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line3.x1,_line3.y1,this.parent as Application);
					_line1.preLine 	= _line2;
					_line2.nextLine = _line1;
					_line2.preLine 	= _line3;
					_line3.nextLine = _line2;
					_line3.preLine 	= _line4;
					_line4.nextLine = _line3;
					_line4.preLine = p_uLine.preLine;
					if(null!=p_uLine.preLine){
						p_uLine.preLine.nextLine = _line4;
					}
					_line1.out_flow_focusNode = p_focusNode;
					LineUtils.removeLine(p_uLine);	
					_line1.drawLine();
					_line2.drawLine();
					_line3.drawLine();
					_line4.drawLine();	
					_line1.in_flow_focusNode = this._top_node;
					this._outLine = _line1;	
					p_focusNode.setStyle("backgroundColor","#ffffff");
				}
			}			
		}
		private function _onTop_FromDrop(p_focusNode:Node,p_uLine:ULine,p_moveNode:Node):void{
			//横线；
			if(p_uLine.x1	==	p_uLine.x2){
				
			}else if(p_uLine.y1	==	p_uLine.y2){
				//竖线；
				if(this.y + p_focusNode.y > p_uLine.y2){
					//箭头在上方流程节点的上方
					//1.创建一条横线,坐标(_uLine.x1,_n.y)-(_n.x,_n.y)
					var _line1:ULine = new ULine(this.x+p_focusNode.x,p_uLine.y1,this.x+p_focusNode.x,this.y+p_focusNode.y,this.parent as Application);
					//2.创建竖线,坐标(this.x1,this.y1)-(_uLine.x1,_n.y);
					var _line2:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line1.x1,_line1.y1,this.parent as Application);
					_line2.nextLine	 = _line1;
					_line1.preLine 	 = _line2;
					LineUtils.removeLine(p_uLine);
					_line2.drawLine();
					_line1.drawLine();
					_line1.in_flow_focusNode = p_focusNode;
					this._outLine = _line1;
				}else{	
					//开始点在流程节点的下方	
					var _line1:ULine = new ULine(this.x+p_focusNode.x,this.y + p_focusNode.y,this.x+p_focusNode.x,this.y + p_focusNode.y-40,this.parent as Application);
					var _x2:int = p_uLine.x1 + (p_uLine.x2-p_uLine.x1)/2;//
					
					var _line2:ULine = new ULine(_line1.x2,_line1.y2,_x2,_line1.y2,this.parent as Application);	
					var _line3:ULine = new ULine(_line2.x2,_line2.y2,_x2,p_uLine.y1,this.parent as Application);
					var _line4:ULine = new ULine(_line3.x2,_line3.y2,p_uLine.x2,p_uLine.y2,this.parent as Application);
					_line1.nextLine 	= _line2;
					_line2.preLine = _line1;
					_line2.nextLine 	= _line3;
					_line3.preLine = _line2;
					_line3.nextLine 	= _line4;
					_line4.preLine = _line3;
					_line4.nextLine = p_uLine.nextLine;
					if(null!=p_uLine.nextLine){
						p_uLine.nextLine.preLine = _line4;
					}
					_line1.out_flow_focusNode = p_focusNode;
					LineUtils.removeLine(p_uLine);	
					_line1.drawLine();
					_line2.drawLine();
					_line3.drawLine();
					_line4.drawLine();	
					_line1.out_flow_focusNode = this._top_node;
					this._inLine = _line1;	
					p_focusNode.setStyle("backgroundColor","#ffffff");
				}
			}			
		}
		//左侧节点,开始箭头放下
		private function _onLeft_FromDrop(p_focusNode:Node,p_uLine:ULine,p_moveNode:Node):void{
			//竖线；
			if(p_uLine.x1	==	p_uLine.x2){
				if((this.x+p_focusNode.x - p_uLine.x2)>0){
					//  |     
					//  |     
					///   ---+---
					///   |      |
					//    +      +
					//    |      |
					//	  ---+---
					//箭头线在流程节点的左侧;
					//1.创建一条横线,坐标(_uLine.x1,_n.y)-(_n.x,_n.y)
					var _line1:ULine = new ULine(this.x+p_focusNode.x,this.y+p_focusNode.y,p_uLine.x1,this.y+p_focusNode.y,this.parent as Application);
					//2.创建竖线,坐标(this.x1,this.y1)-(_uLine.x1,_n.y);
					var _line2:ULine = new ULine(_line1.x2,_line1.y2,p_uLine.x2,p_uLine.y2,this.parent as Application);
					_line2.preLine	 = _line1;
					_line1.nextLine 	 = _line2;
					_line2.nextLine = p_uLine.nextLine;
					if(null!=p_uLine.nextLine){
						p_uLine.nextLine.preLine = _line2;
					}
					LineUtils.removeLine(p_uLine);
					_line2.drawLine();
					_line1.drawLine();							
					_line1.out_flow_focusNode = p_focusNode;
					this._inLine = _line1;
				}else{
					//       |
					//       |
					///   ---+---
					///   |      |
					//    +      +
					//    |      |
					//	  ---+---
					//箭头线在流程左侧节点的右侧;
					if(null!=p_uLine.preLine){
						var _line1:ULine = new ULine(this.x+p_focusNode.x-40,this.y + p_focusNode.y,this.x+p_focusNode.x,this.y + p_focusNode.y,this.parent as Application);								
						var _line2:ULine = new ULine(_line1.x1,p_uLine.y1,_line1.x1,_line1.y1,this.parent as Application);	
						var _line3:ULine = new ULine(p_uLine.preLine.x1,p_uLine.preLine.y1,_line2.x1,_line2.y1,this.parent as Application);	
						_line1.preLine 	= _line2;
						_line2.nextLine = _line1;
						_line2.preLine  = _line3;
						_line3.nextLine = _line2;
						_line3.preLine = p_uLine.preLine.preLine;
						if(null!=p_uLine.preLine.preLine){
							p_uLine.preLine.preLine.nextLine = _line3;
						}
						LineUtils.removeLine(p_uLine.preLine);
						LineUtils.removeLine(p_uLine);	
						_line1.drawLine();
						_line2.drawLine();
						_line3.drawLine();
						_line1.in_flow_focusNode = this._left_node;
						_outLine = _line1;	
						p_focusNode.setStyle("backgroundColor","#ffffff");
					}else{
						var _line1:ULine = new ULine(this.x+p_focusNode.x-40,this.y + p_focusNode.y,this.x+p_focusNode.x,this.y + p_focusNode.y,this.parent as Application);
						var _y2:int = p_uLine.y1 + (p_uLine.y2-p_uLine.y1)/2;//
						var _line2:ULine = new ULine(_line1.x1,_y2,_line1.x1,_line1.y1,this.parent as Application);	
						var _line3:ULine = new ULine(_line2.x1,_y2,_line2.x1,_line2.y1,this.parent as Application);
						var _line4:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line3.x1,_line3.y1,this.parent as Application);
						_line1.preLine 	= _line2;
						_line2.nextLine = _line1;
						_line2.preLine 	= _line3;
						_line3.nextLine = _line2;
						_line3.preLine 	= _line4;
						_line4.nextLine = _line3;
						_line4.preLine = p_uLine.preLine;
						if(null!=p_uLine.preLine){
							p_uLine.preLine.nextLine = _line4;
						}
						_line1.out_flow_focusNode = p_focusNode;
						LineUtils.removeLine(p_uLine);	
						_line1.drawLine();
						_line2.drawLine();
						_line3.drawLine();
						_line4.drawLine();	
						_line1.in_flow_focusNode = _fn._left_node;
						var _fn:FlowNode = p_uLine.in_flow_focusNode.parent as 	FlowNode;
						_fn._outLine = _line1;	
						p_focusNode.setStyle("backgroundColor","#ffffff");
						this._outLine = p_uLine;
					}
				}
			}else if(p_uLine.y1	==	p_uLine.y2){
				if(this.x + p_focusNode.x > p_uLine.x1){
					if(null==p_uLine.nextLine){
						//一条横线;
						var _x2:int = p_uLine.x2 + (this.x + p_focusNode.x -p_uLine.x2)/2;//
						var _line1:ULine = new ULine(this.x+p_focusNode.x,this.y + p_focusNode.y,_x2,this.y + p_focusNode.y,this.parent as Application);

						var _line2:ULine = new ULine(_line1.x2,_line1.y2,_x2,p_uLine.y2,this.parent as Application);	
						var _line3:ULine = new ULine(_line2.x2,_line2.y2,p_uLine.x2,p_uLine.y2,this.parent as Application);
					
						_line1.nextLine 	= _line2;
						_line2.preLine 		= _line1;
						_line2.nextLine 	= _line3;
						_line3.preLine 		= _line2;
						_line3.nextLine 	= p_uLine.nextLine;
						_line3.in_flow_focusNode = p_uLine.in_flow_focusNode;
						if(null!=p_uLine.in_flow_focusNode){
							var _flowNode:FlowNode = p_uLine.in_flow_focusNode.parent as FlowNode;
							_flowNode._outLine = _line1;
						}
						LineUtils.removeLine(p_uLine);	
						_line1.drawLine();
						_line2.drawLine();
						_line3.drawLine();
						_line1.out_flow_focusNode = this._left_node;
						this._inLine = _line1;	
						p_focusNode.setStyle("backgroundColor","#ffffff");						
					}else{
						//横线左侧
						var a:Alert;
						Alert.show("横线左侧fromdrop");
						
						p_uLine.arrowLineNode.x = this.x	+	p_focusNode.x;
						p_uLine.arrowLineNode.y = this.y	+	p_focusNode.y;
						p_uLine.out_flow_focusNode = p_focusNode;
						p_uLine._reFromToDrawLine(p_uLine.fromLineNode);				
						p_focusNode.setStyle("backgroundColor","#ffffff");
						this._inLine = p_uLine;
					}
				}else{
					////     ----
					///   ---+---
					///   |      |
					//    +      +
					//    |      |
					//	  ---+---
					var _line1:ULine = new ULine(this.x+p_focusNode.x-40,this.y + p_focusNode.y,this.x+p_focusNode.x,this.y + p_focusNode.y,this.parent as Application);
					var _y2:int = p_uLine.y1 + (p_uLine.y2-p_uLine.y1)/2;//
					var _line2:ULine = new ULine(_line1.x1,p_uLine.y1,_line1.x1,_line1.y1,this.parent as Application);	
					var _line3:ULine = new ULine(p_uLine.x1,p_uLine.y1,_line2.x1,_line2.y1,this.parent as Application);
				
					_line1.preLine 	= _line2;
					_line2.nextLine = _line1;
					_line2.preLine 	= _line3;
					_line3.nextLine = _line2;
					_line3.preLine 	= p_uLine.preLine;

					if(null!=p_uLine.preLine){
						p_uLine.preLine.nextLine = _line3;
					}
					LineUtils.removeLine(p_uLine);	
					_line1.drawLine();
					_line2.drawLine();
					_line3.drawLine();
					_line1.in_flow_focusNode = this._left_node;
					this._outLine = _line1;	
					p_focusNode.setStyle("backgroundColor","#ffffff");
				}
//				//竖线；
//				p_uLine.toNode.x = this.x	+	p_focusNode.x;
//				p_uLine.toNode.y = this.y	+	p_focusNode.y;
//				p_uLine._to_flow_node = p_focusNode;
////				_uLine.drawLine();
//				p_uLine._reArrowDrawLine(p_uLine.toNode);				
//				p_focusNode.setStyle("backgroundColor","#ffffff");
//				this._fromLine = p_uLine;	
			}			
		}
		private function _onFromDrop(p_focusNode:Node,p_uLine:ULine,p_moveNode:Node):void{			
			if(null!=p_uLine.out_flow_focusNode)	{
				var _fn:FlowNode = p_uLine.out_flow_focusNode.parent as FlowNode;
				_fn._inLine = null;
			}
			if("TOP"==p_focusNode._flow_node_type){
				this._onTop_FromDrop(p_focusNode,p_uLine,p_moveNode);					
			}if("LEFT"==p_focusNode._flow_node_type){
				this._onLeft_FromDrop(p_focusNode,p_uLine,p_moveNode);					
			}else{
				p_uLine.fromLineNode.x = this.x	+	p_focusNode.x;
				p_uLine.fromLineNode.y = this.y	+	p_focusNode.y;
				p_uLine.out_flow_focusNode = p_focusNode;
				p_uLine._reFromToDrawLine(p_uLine.fromLineNode);
				p_focusNode.setStyle("backgroundColor","#ffffff");
				this._inLine = p_uLine;	
			}
			
		}
		private function onDragDrop(event:DragEvent):void{
			//流程节点选择器;
			var _n:Node = Node(event.currentTarget);			
			var _uLine:ULine = event.dragSource.dataForFormat("line") as ULine;
			var _moveNode:Node = event.dragInitiator as Node;
			//线头
			if(null==_uLine.preLine && "F"==_moveNode._line_node_type){
				_onFromDrop(_n,_uLine,_moveNode);			
			}
			//箭头
			if(null==_uLine.nextLine && "T"==_moveNode._line_node_type){
				_onArrowDrop(_n,_uLine,_moveNode);	
			}
		}
		public function drawRect():void{
			this.graphics.beginFill(0xffffff,1);
			this.graphics.lineStyle(1,0x000000,2);
			this.graphics.drawRect(5,5,this.width-10,this.height-10);
			this.graphics.endFill();
		}
		public function startDragging(event:MouseEvent):void{
			event.currentTarget.startDrag();
		}
		public function stopDragging(event:MouseEvent):void{
			event.currentTarget.stopDrag();	
			//调整该节点关联线;
			if(null!=_inLine){
				//调整出口线
				_inLine.fromLineNode.x 	= this.x + _inLine.out_flow_focusNode.x;
				_inLine.fromLineNode.y	= this.y + _inLine.out_flow_focusNode.y;
				_inLine._reFromToDrawLine(_inLine.fromLineNode);
			}
			if(null!=_outLine){
				//调整入口线;
				_outLine.arrowLineNode.x 	= this.x + _outLine.in_flow_focusNode.x;
				_outLine.arrowLineNode.y	= this.y + _outLine.in_flow_focusNode.y;
				_outLine._reArrowDrawLine(_outLine.arrowLineNode);
			}
		}
		
	}
}